Page({
    /**
   * 页面的初始数据
   */
  data: {
    //pdf文档
    pdfList: {},
    examineText: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let { id } = options;

  },
  uploadPDF() {
    console.log("uploadPDF")
    wx.chooseMessageFile({
      //最多可以选择的文件数量，最多是0-100
      count: 1,
      //指打开文件的类型
      type: "file",
      success: (res) => {
        let path = res.tempFiles[0].path
        let suffix = path.split(".")[1]
        if (suffix !="pdf") {
          console.log("只能上传pdf或者word文件")
          return
        }
        wx.uploadFile({
          url: "http://127.0.0.1:8081/upload",
          header: {
            "Content-Type": "multipart/form-data"
          },
          name: "file",
          filePath: path,
          success: (res) => {
            if (res.statusCode == 200) {
              console.log("上传成功")
            } else {
              console.error(res.data)
            }
          }
        })
      }
    })
  },
  //上传word文档
  uploadWord() {
    console.log("uploadWord")
    wx.chooseMessageFile({
      //最多可以选择的文件数量，最多是0-100
      count: 1,
      //指打开文件的类型
      type: "file",
      success: (res) => {
        let path = res.tempFiles[0].path
        let suffix = path.split(".")[1]
        if (suffix !="docx") {
          console.log("只能上传pdf或者word文件")
          return
        }
        wx.uploadFile({
          url: "http://127.0.0.1:8081/upload",
          header: {
            "Content-Type": "multipart/form-data"
          },
          name: "file",
          filePath: path,
          success: (res) => {
            if (res.statusCode == 200) {
              console.log("上传成功")
            } else {
              console.error(res.data)
            }
          }
        })
      }
    })
  },
  //加载pdf列表
  loadPdfList() {
    wx.request({
      url: "http://127.0.0.1:8081/fileList",
      method: "GET",
      success: (res) => {
        this.setData({
          pdfList: res.data
        })
      }
    })
  },

  //加载pdf列表
  loadPdfList() {
    wx.request({
      url: "http://127.0.0.1:8081/fileList",
      method: "GET",
      success: (res) => {
        this.setData({
          pdfList: res.data
        })
      }
    })
  },
  //查看pdf文档
  lookPDF(e) {
    wx.showLoading({
      title:"加载中...",
      mask:true
    })
    let imgUrl = e.currentTarget.dataset.src
    wx.downloadFile({
      url: "http://127.0.0.1:8081/download?file=" + imgUrl,
      success: (res) => {
        if (res.statusCode === 200) {
          setTimeout(() => {
            wx.openDocument({
              filePath:res.tempFilePath,
              fileType:["pdf","docx"]
            })
            wx.showToast({
              title:"加载成功！.",
              icon:"success",
              duration:2000,

            })
            wx.hideLoading()
          }, 1500);
         }

      },fail(){
        wx.hideLoading()
      }
    })
  },
 
  //加载pdf列表
  examinePdfList() {
    wx.request({
      url: "http://127.0.0.1:8081/examinetext",
      method: "POST",
      success: (res) => {
        this.setData({
          examineText: res.data
        })
      }
    })
  }
})